home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-12-04 | 3.0 KB | 59 lines | [TEXT/MPS ] |
- This is a small sample of how YOU (yes, you) can add functionality
- to ANYONE's AppleEvent aware application.
- As you read in Inside Mac VI, The AppleEvent manager provides facilities
- for coercing (changing) one type of AppleEvent data to another. It has some
- built-in coercions, and it allows you to make your own for your application.
-
- BUT, it also allows you to create SYSTEM level coercion routines.
- If you create a system level coercer, that means that ANYONE on that
- machine can use it, and they may never even know that they did!
- Take an example;
- Someone has created an Application that returns graphic images
- in AppleEvents, but that weasel ONLY returns them as TIFF, since he or
- she hates PICT.
- Another application asks for the graphic in the first application's window with a
- GetData event.
- The snobby application returns a TIFF image.
- The asking application doesn't know TIFF, and does this;
- myErr = AEGetParamDesc(reply, keyDirectObject, typePICT, &theData);
- Oh No! They get back an error, errAECoercionFail, because the AppleEvent Manager
- on its own can't change the returned TIFF into a PICT.
- Enter our hero (you)
- You are a really smart graphic person, and you know all about converting
- PICT to TIFF. You make a coercion routine that converts PICT to TIFF,
- and install it as a System coercion handler.
- Then, when the TIFF unaware app does this;
- myErr = AEGetParamDesc(reply, keyDirectObject, typePICT, &theData);
- The AppleEvent manager KNOWS that you have installed a converter for TIFF to PICT
- and calls your converter. You do the job, and the asking application gets
- a PICT without even knowing that a coercion happened! It's Magic!
-
- Coercion routines are very powerful, you can add functonality to all the
- applications on a machine by creating and installing converters from one type to
- another. The possibilities are limitless on the types of conversions you
- can perform.
-
- So here's an example of how to write an INIT that installs some system coercion
- routines on a machine. It installs two kinda trivial converters, that convert from
- a PString type (my own type, the AE Registry does not define a PString) to
- typeChar, and vice-versa [Note: If you write a converter, please write one
- that converts in both directions, it'll be much more useful that way].
- I use this coercion in some sample code I wrote, so I can work easily with the
- Object Model (which expects typeChar for many things) and the Mac ToolBox (which
- likes PStrings for many things).
-
- After the installation, any application that tries to get a typeChar as a
- typeMyPString will work smoothly, without having to know how to do the conversion
- themselves.
-
- Obviously, your converter will be a lot more useful than mine. Maybe you will write
- the PICT to TIFF, or TEXT to PICT, or whatever.
-
- I actually have been waiting for someone in the commercial world to do this
- already, I think there's money in it.
-
- But anyway, look at the sample, read the section on coercion routines CAREFULLY,
- and see what you can come up with to help the world!
-
- C.K. Haun
- Apple Developer Tech Support